Skip to content

B2B Provisioning: Add interstitial page to process redemption code retrieval #2422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 15, 2025

Conversation

jkachel
Copy link
Contributor

@jkachel jkachel commented Aug 7, 2025

What are the relevant tickets?

Partially closes mitodl/hq#7954

Description (What does it do?)

Adds an interstitial page (and thus a URL) users can use to redeem an enrollment code to gain access to a B2B contract.

This uses the API that is added in mitodl/mitxonline#2866 - so this code is blocked until that PR is merged and the API client is updated and built.

But basically this allows us to have a URL that's /attach/<code> which drops the user at a page that hits the redemption API, and then redirects them to the dashboard when it's done. There's some minimal text to explain what's going on but there's no other UI or processing.

Screenshots (if appropriate):

  • Desktop screenshots
image

How can this be tested?

  • Follow the instructions on better bad data handling for the org dashboard #2427 up until and including creating the B2B organization and adding courses / programs to a contract
  • Once you have a contract, list the contracts with docker compose exec web ./manage.py b2b_list contracts. Once you have the ID for the contract you made, list the codes for it. For example, assuming your ID is 30: docker compose exec web ./manage.py b2b_list contracts --codes 30
  • Log in as a user that is not part of any orgs (I used [email protected]) in an incognito window
  • Visit /attach/the-code, replacing the-code with the code you got from the above command
  • You should see a brief message, then be redirected to the dashboard
  • From there, you should see a tab for the org you just enrolled in
  • Click the org tab to load the org dashboard, then click start module on any of the courses
  • Verify that enrollment worked

Additional context

This is mostly an MVP for this - it does the bare minimum. It would probably be good to make this a bit nicer - it'd be nice to display an alert on the dashboard to tell the user that they're now in a contract or something along those lines.

@jkachel jkachel added the Needs Review An open Pull Request that is ready for review label Aug 7, 2025
@jkachel
Copy link
Contributor Author

jkachel commented Aug 7, 2025

Marking this as needs review - this works, and the tests pass so far (but the linting/formatting doesn't). So, it can be reviewed as-is. This will absolutely need some work to pull in the real API from the client when that's ready.

@gumaerc gumaerc force-pushed the jkachel/7954-add-b2b-code-redemption-interstitial branch from 72fce5a to 4973876 Compare August 14, 2025 17:36
@gumaerc gumaerc marked this pull request as ready for review August 14, 2025 21:09
@gumaerc gumaerc mentioned this pull request Aug 14, 2025
@jonkafton jonkafton self-assigned this Aug 15, 2025
Copy link
Contributor

@jonkafton jonkafton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of render cycle change requests, otherwise looks good!

Comment on lines 28 to 30
if (isSuccess) {
redirect(urls.DASHBOARD_HOME)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redirect should not happen during render. Fix e.g.

Suggested change
if (isSuccess) {
redirect(urls.DASHBOARD_HOME)
}
React.useEffect(() => {
if (isSuccess) {
redirect(urls.DASHBOARD_HOME)
}
}, [isSuccess])

enrollment_code: code,
})

React.useEffect(() => attach(), [attach])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function reference could change between renders because it comes from useMutation, so may run more than once.

We can give it an empty dependency array to just run once,

Suggested change
React.useEffect(() => attach(), [attach])
React.useEffect(() => attach(), [])

Though still not 100% guaranteed to run once. May not be a problem for a idempotent endpoint, but to guarantee it runs once we could track with a ref:

  const hasRun = useRef(false)

  React.useEffect(() => {
    if (!hasRun.current) {
      attach()
      hasRun.current = true
    }
  }, [])

@gumaerc gumaerc force-pushed the jkachel/7954-add-b2b-code-redemption-interstitial branch from 0e221b3 to 52cb1d8 Compare August 15, 2025 17:32
Copy link
Contributor

@jonkafton jonkafton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

@gumaerc gumaerc merged commit 6d25db1 into main Aug 15, 2025
13 checks passed
@gumaerc gumaerc deleted the jkachel/7954-add-b2b-code-redemption-interstitial branch August 15, 2025 23:00
@jonkafton jonkafton removed the Needs Review An open Pull Request that is ready for review label Aug 18, 2025
This was referenced Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants